using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

namespace minims_lib
{
	public class MinimsServer
	{
		Hashtable services;

		SSDP_SERVER ssdp_server;
		HTTP_SERVER http_server;
		FileManager file_manager;

		private bool Started;

		public bool Start(string serverRoot)
		{
			services = new Hashtable();

			services.Add("ConfigManager", new ConfigManager(serverRoot));
			ConfigManager configManager = ((ConfigManager)services["ConfigManager"]);
			

			services.Add("ContentDirectory", new ContentDirectory(configManager));
			services.Add("X_MS_MediaReceiverRegistrar", new X_MS_MediaReceiverRegistrar(configManager));

			file_manager = new FileManager();
			file_manager.Add(new MinimsFile(FILETYPE.System, "/System/", RootDevice.GetRootDeviceXml(configManager)));
			file_manager.Add(new MinimsFile(FILETYPE.System, "/System/ContentDirectory/ContentDirectory.xml", ContentDirectory.GetDescription()));
			file_manager.Add(new MinimsFile(FILETYPE.System, "/System/X_MS_MediaReceiverRegistrar/X_MS_MediaReceiverRegistrar.xml", X_MS_MediaReceiverRegistrar.GetDescription()));

			http_server = new HTTP_SERVER(services, file_manager, configManager.User.Port);
			ssdp_server = new SSDP_SERVER(configManager);

			ssdp_server.Start();
			http_server.Start();

			this.Started = true;

			return true;
		}	
		public void Stop()
		{
			http_server.Stop();
			http_server = null;
			ssdp_server.Stop();
			ssdp_server = null;
		}
		public bool UpdateContent(List<string> folders)
		{
			if (Started)
			{
				((ContentDirectory)services["ContentDirectory"]).Update(folders);
				return true;
			}
			return false;
		}
		public long ContentSize
		{
			get
			{
				return ((ContentDirectory)services["ContentDirectory"]).size;
			}
		}
	}
}
